package com.ruoyi.web.controller.code;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.domain.Experts;
import com.ruoyi.web.service.IExpertsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专家信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-31
 */
@RestController
@RequestMapping("/code/experts")
public class ExpertsController extends BaseController
{
    @Autowired
    private IExpertsService expertsService;

    /**
     * 查询专家信息列表
     */
    @PreAuthorize("@ss.hasPermi('code:experts:list')")
    @GetMapping("/list")
    public TableDataInfo list(Experts experts)
    {
        startPage();
        List<Experts> list = expertsService.selectExpertsList(experts);
        return getDataTable(list);
    }

    /**
     * 导出专家信息列表
     */
    @PreAuthorize("@ss.hasPermi('code:experts:export')")
    @Log(title = "专家信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Experts experts)
    {
        List<Experts> list = expertsService.selectExpertsList(experts);
        ExcelUtil<Experts> util = new ExcelUtil<Experts>(Experts.class);
        util.exportExcel(response, list, "专家信息数据");
    }

    /**
     * 获取专家信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('code:experts:query')")
    @GetMapping(value = "/{expertId}")
    public AjaxResult getInfo(@PathVariable("expertId") Long expertId)
    {
        return success(expertsService.selectExpertsByExpertId(expertId));
    }

    /**
     * 新增专家信息
     */
    @PreAuthorize("@ss.hasPermi('code:experts:add')")
    @Log(title = "专家信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Experts experts)
    {
        return toAjax(expertsService.insertExperts(experts));
    }

    /**
     * 修改专家信息
     */
    @PreAuthorize("@ss.hasPermi('code:experts:edit')")
    @Log(title = "专家信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Experts experts)
    {
        return toAjax(expertsService.updateExperts(experts));
    }

    /**
     * 删除专家信息
     */
    @PreAuthorize("@ss.hasPermi('code:experts:remove')")
    @Log(title = "专家信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expertIds}")
    public AjaxResult remove(@PathVariable Long[] expertIds)
    {
        return toAjax(expertsService.deleteExpertsByExpertIds(expertIds));
    }
}
